@extends('Admin.layout.layout')

@section('content')
 <div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">日记列表</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>   
 <div class="dataTable_wrapper">
  <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
    <div class="row">
    <form action="{{ url('/admin/day/list') }}" method="get">
      <div class="col-sm-6">
        <div class="dataTables_length" id="dataTables-example_length">
                     <label>显示
                              <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                                    <option value="10" @if(!empty($request['num']) && $request['num'] == 10) { selected } @endif>10</option>
                                    <option value="25" @if(!empty($request['num']) && $request['num'] == 25) { selected } @endif>25</option>
                                    <option value="50"  @if(!empty($request['num']) && $request['num'] == 50) { selected } @endif>50</option>
                                    <option value="100"  @if(!empty($request['num']) && $request['num'] == 100) { selected } @endif>100</option>
                              </select> 条
                     </label>
        </div>
      </div>
      <div class="col-sm-6">
        <div id="dataTables-example_filter" class="dataTables_filter">
          <label>日记标题:
            <input name="keywords" value="@if(!empty($request['keywords'])){{$request['keywords']}}@endif" type="search" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" />
            <button class="btn btn-info" type="submit">查询</button>
          </label>
        </div>
      </div>
      </form>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
          <thead>
            <tr role="row">
              <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="width: 100px;">ID</th>
              <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 147px;">用户名</th>
              <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 168px;">标题</th>
              <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 168px;">发表时间</th>
              <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 108px;">浏览次数</th>
              <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width:15%">编辑</th>
              </tr>
          </thead>
          <tbody>
            @foreach($cates as $k=>$v)
            <tr class="gradeA odd" role="row">
              <td class="sorting_1 sid">{{ $v->id }}</td>
              <td>{{ $v->uname }}</td>
              <td><div  style="overflow:hidden;height:20px;width:200px;">{{ $v->title }}</div></td>
              <td class="center">{{ $v->dtime }}</td>
              <td class="center">{{ $v->count }}</td>
              <td class="cente sorting_1"> <a class="fa fa-trash-o  delete" >删除</a> | <a href="{{url('admin/day/edit',['id'=>$v->id])}}"class="fa fa-wrench">修改</a>
              </td>
            </tr>
            @endforeach  
          </tbody>
        </table>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-6">
        <div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite">Showing 1 to 10 of 57 entries</div></div>
      <div class="col-sm-6">
        <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
          {!! $cates->appends($request)->render() !!}
        </div>
      </div>
    </div>
  </div>
</div>
@endsection
@section('myjs')
   <script type="text/javascript">
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
      // 绑定单击事件
      $('.delete').click(function(){

        var id=$(this).parents('tr').find('.sid').html();
        var dd=$(this);

        $.post('/admin/day/delete',{id:id},function(data){

            if(data==1){
                dd.parents('tr').remove();
            }else{
                alert('删除失败');
            }
        })
      });

   </script>
@endsection